﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using Global;

namespace Clipper.ClipperUserControl
{
    /// <summary>
    /// UserMonitor.xaml 的交互逻辑
    /// </summary>
    public partial class UserMonitor : UserControl
    {
        public UserMonitor()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            
        }
        public void DataBind()
        {
            if (ServiceProvider.Monitor.MonitorCanvas == null)
            {
                ServiceProvider.Monitor.MonitorCanvas = MonitorCanvas;
                ServiceProvider.Monitor.Transportation = Transportation;

                ServiceProvider.DeliverPosition = GetCanvasPosition(DeliverPosition);
                ServiceProvider.Reagent1Position = GetCanvasPosition(Reagent1Position);
                ServiceProvider.Reagent2Position = GetCanvasPosition(Reagent2Position);
                ServiceProvider.WashTank1Position = GetCanvasPosition(WashTank1Position);
                ServiceProvider.WashTank2Position = GetCanvasPosition(WashTank2Position);
                ServiceProvider.SubstractPosition = GetCanvasPosition(SubstractPosition);
                ServiceProvider.IncubationBox = GetCanvasPosition(IncubationBox);
                ServiceProvider.WaitReactionPosition = GetCanvasPosition(WaitReaction);
                ServiceProvider.DetectionHoousePosition = GetCanvasPosition(DetectionHousePosition);
                ServiceProvider.RecyleBinPosition = GetCanvasPosition(RecyleBinPosition);

                datDetectedStrips.ItemsSource = ServiceProvider.Monitor.CompleteStrips;
                datRunningStrips.ItemsSource = ServiceProvider.Monitor.RunningStrips;
                this.DataContext = ServiceProvider.Monitor;
            }
        }
        private void Move(FrameworkElement rect, Point toPoint)
        {
            double fromX = Canvas.GetLeft(rect);
            double fromY = Canvas.GetTop(rect);
             
            //创建移动动画
            Storyboard storyboard = new Storyboard();
            //创建X轴方向动画
            DoubleAnimation doubleAnimation = new DoubleAnimation(
               fromX,
               toPoint.X,
               new Duration(TimeSpan.FromSeconds(1))
               );
            Storyboard.SetTarget(doubleAnimation, rect);
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Left)"));
            storyboard.Children.Add(doubleAnimation);
            //创建Y轴方向动画
            doubleAnimation = new DoubleAnimation(
                fromY,
                toPoint.Y,
                new Duration(TimeSpan.FromSeconds(1))
                );
            Storyboard.SetTarget(doubleAnimation, rect);
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Top)"));
            storyboard.Children.Add(doubleAnimation);

            //动画播放
            storyboard.Begin();
        }

        public Point GetCanvasPosition(FrameworkElement element)
        {
            return new Point(Canvas.GetLeft(element), Canvas.GetTop(element));
        }

        private void btnCx_Click(object sender, RoutedEventArgs e)
        {
            BLL.DetectChain.IncubationBox.IncubationControl.GetTemperature();
        }
    }
}
